package com.yuhanginfo.modules.web.util;

import com.yuhanginfo.common.utils.ReadProperties;
import com.yuhanginfo.modules.web.entity.PayData;
import com.yuhanginfo.modules.web.entity.WebPayHistory;
import com.yuhanginfo.modules.web.entity.WebOrders;

/**
 * 支付接口调用
 *
 */
public class PayUtils {
	
	private PayUtils(){}
	private static String mchntCd = ReadProperties.ReadByName("pay_mchnt_cd");
	private static String orderPayType = ReadProperties.ReadByName("pay_order_pay_type");
	private static String orderValidTime = ReadProperties.ReadByName("pay_order_valid_time");
	private static String issInsCd = ReadProperties.ReadByName("pay_iss_ins_cd");
	private static String ver = ReadProperties.ReadByName("pay_ver");
	private static String mchntKey = ReadProperties.ReadByName("pay_mchnt_key");
	private static String rem = ReadProperties.ReadByName("pay_rem");
	private static String label = ReadProperties.ReadByName("pay_return_address");
	
	/**
	 * 跳转到富友支付页面
	 */
	public static PayData goPay(WebOrders order){
		
		PayData payData = new PayData();
		String orderId = order.getCode();
		String orderAmt = order.getMoney().toString().replace(".", "");
		String pageNotifyUrl = label+"/payment/paySuccess";
		String backNotifyUrl = "";
		String goodsDisplayUrl = label + "/order/orderDetail?ordersCode="+order.getCode()+"&transportType="+order.getTransportType()+"&id="+order.getId();
		String goodsName = "";
		String signDataStr =mchntCd + "|" + orderId+ "|" +orderAmt+ "|" +orderPayType+ "|" +
                    		pageNotifyUrl+ "|" +backNotifyUrl+ "|" +orderValidTime+ "|" +
                     		issInsCd+ "|" +goodsName+ "|" +goodsDisplayUrl+ "|" 
                 			+rem+ "|" +ver+ "|" + mchntKey;
		String md5 = MD5.MD5Encode(signDataStr);
		payData.setMd5(md5);
		payData.setMchntCd(mchntCd);
		payData.setOrderId(orderId);
		payData.setOrderAmt(orderAmt);
		payData.setOrderPayType(orderPayType);
		payData.setPageNotifyUrl(pageNotifyUrl);
		payData.setBackNotifyUrl(backNotifyUrl);
		payData.setOrderValidTime(orderValidTime);
		payData.setIssInsCd(issInsCd);
		payData.setGoodsName(goodsName);
		payData.setGoodsDisplayUrl(goodsDisplayUrl);
		payData.setRem(rem);
		payData.setVer(ver);
		return payData;
	}
	
	/**
	 * 还款
	 */
	public static PayData returnMoney(String money, String returnCode, String invoiceInfoId){
		PayData payData = new PayData();
		WebPayHistory payHistory = new WebPayHistory();
		payHistory.setPayCode("1");
		String orderId = returnCode;
		String orderAmt = money.replace(".", "");
		String pageNotifyUrl = label+"/home/returnMoneySuccess?invoiceInfoId="+invoiceInfoId;
		String backNotifyUrl = "";
		String goodsDisplayUrl = "";
		String goodsName = "";
		String signDataStr =mchntCd + "|" + orderId+ "|" +orderAmt+ "|" +orderPayType+ "|" +
        		pageNotifyUrl+ "|" +backNotifyUrl+ "|" +orderValidTime+ "|" +
         		issInsCd+ "|" +goodsName+ "|" +goodsDisplayUrl+ "|" 
     			+rem+ "|" +ver+ "|" + mchntKey;
		String md5 = MD5.MD5Encode(signDataStr);
		payData.setMd5(md5);
		payData.setMchntCd(mchntCd);
		payData.setOrderId(orderId);
		payData.setOrderAmt(orderAmt);
		payData.setOrderPayType(orderPayType);
		payData.setPageNotifyUrl(pageNotifyUrl);
		payData.setBackNotifyUrl(backNotifyUrl);
		payData.setOrderValidTime(orderValidTime);
		payData.setIssInsCd(issInsCd);
		payData.setGoodsName(goodsName);
		payData.setGoodsDisplayUrl(goodsDisplayUrl);
		payData.setRem(rem);
		payData.setVer(ver);
		return payData;
	}

}
